#ifndef _sbrush_pantomime_player_h_
#define _sbrush_pantomime_player_h_

#include "sbrush_instrument.h"
#include "sbrush_player.h"
#include "sbrush_pantomime.h"
#include "sbrush_spectral_model_player.h"
#include "dag_threading.h"

#include <set>
#include <queue>
#include <deque>

namespace sbrush {

	class SampleCompare {
	public:
		bool operator() (const Sample*& lhs, const Sample*& rhs) const {
			return rhs->smsFrame < lhs->smsFrame;
		}
	};
	
	class PantomimePlayer : public Player,
							public dag::Runnable 
	{
	public:
		PantomimePlayer();
		virtual ~PantomimePlayer() throw();
		void setPantomime(const Pantomime& pantomime);
		void addListener(InstrumentListener* listener);
		void removeListener(InstrumentListener* listener);
		void start();
		void stop();
		int playHead() const;
		void seek(int pos, Whence whence);
		int length() const;
		void runThread();
		
	private:
		void buildSampleQueue();
		const Pantomime* m_CurrentPantomime;
		mutable dag::Mutex m_PlayMutex;
		SpectralModelPlayer m_SpectralModelPlayer;
		std::set<InstrumentListener*> m_Listeners;
		std::priority_queue<const Sample*, 
			std::deque<const Sample*>, 
			SampleCompare> m_SampleQueue;
		bool m_IsRunning;
		bool m_KeepRunning;
	};
}


#endif